import path from 'path';
import fs from 'fs'
import ora from 'ora';
var zip = require('cross-zip')

const spinner = ora('strat init dem data!').start();
const pwdPath = process.env.PWD;
const zipPath = path.join(pwdPath, './script/dem-data.zip');
const tempPath = path.join(pwdPath, '.temp');

function unzip(filePath: string, targerPath: string) {
  spinner.info('upzip ' + filePath)
  spinner.info('upzip...')
  zip.unzip(filePath, targerPath)
  spinner.info('upzip success')
}


function clearFiles(filePath: string) {
  if (fs.existsSync(filePath)) {
    spinner.info("rm " + filePath)
    spinner.info("deleting please wait. . . ")
    fs.rmSync(filePath, {recursive: true, force: true})
  }
  spinner.info("mkdir " + filePath)
  fs.mkdirSync(filePath)
}

function init() {
  // 清除临时文件
  clearFiles(tempPath)
  // 解压到临时文件
  unzip(zipPath, tempPath)
  // 生成层级文件
}

init()